package com.pan.utils;

import java.awt.*;

public enum MyMouseInfo {
    INSTANCE;
    //注意这这段代码是在window背景下写的,我不知道迁移到别的平台是否会有什么问题

    private boolean isEnable;
    private double zoomRatio = 1;
    MyMouseInfo(){
        isEnable = ApplicationConfig.INSTANCE.getZoomEnable();
        if (isEnable){
            String zoomValue = ApplicationConfig.INSTANCE.getZoomValue();//todo
            if (zoomValue.equals("auto")) {
                int screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
                final int standardDpi = 96;//window标准dpi为96
                zoomRatio = (double) screenResolution / standardDpi;
            }else {
                zoomRatio = Double.parseDouble(zoomValue);
            }
        }
    }

    public Point getPoint(){
        Point location = MouseInfo.getPointerInfo().getLocation();
        return isEnable?
                new Point((int) (location.getX()/zoomRatio), (int) (location.getY()/zoomRatio))
                : location;

    }

    public static void main(String[] args) {
        System.out.println(INSTANCE.getPoint().toString());
    }

}
